<template>
  <div class="autumn-container">
    <!-- 面包 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>登录日志</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="autumn-center">
      <!-- 搜索栏 -->
      <div class="query-form">
        <autumn-search :modelValue="queryInfo" @search="search">
          <template #default>
            <el-form-item prop="loginName" label="账户">
              <el-input v-model="queryInfo.loginName" />
            </el-form-item>
            <el-form-item prop="status" label="状态">
              <el-select v-model="queryInfo.status" placeholder="请选择">
                <el-option label="成功" value="1" />
                <el-option label="失败" value="0" />
              </el-select>
            </el-form-item>
          </template>
        </autumn-search>
      </div>

      <!-- 数据表格 -->
      <div class="main-body top">
        <autumn-table :page="page" @changePage="changePage">
          <template #column>
            <el-table-column type="index" label="#" fixed="left" align="center">
              <template #default="scope">
                {{ initIndex(scope.$index) }}
              </template>
            </el-table-column>
            <el-table-column prop="loginName" label="账户" width="150" />
            <el-table-column prop="loginIp" label="登录IP" width="150" />
            <el-table-column prop="createTime" label="登录时间" width="150" align="center"
              :formatter="(row: any) => $moment(row.createTime, 'YYYY-MM-DD HH:mm')" />
            <el-table-column label="状态" align="center" width="80">
              <template #default="scope">
                <el-tag type="success" size="small" v-if="scope.row.status == 1">成功</el-tag>
                <el-tag type="danger" size="small" v-else>失败</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="remark" label="备注" />
          </template>
        </autumn-table>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import useTable from 'src/hooks/useTable'
import { $moment } from 'src/hooks/useCommon'
import { pageLoginLog } from 'src/api/monitor/loginLog'

const { page, initIndex } = useTable()

const queryInfo = reactive({
  loginName: '',
  userName: '',
  gender: '',
  status: ''
})
const changePage = (pageNumber: number, pageSize: number) => {
  page.pageNumber = pageNumber
  page.pageSize = pageSize
  pageLoginLog({ ...queryInfo, pageNumber, pageSize }).then(({ data }) => {
    page.data = data.list
    page.total = data.total
  })
}
const search = () => {
  changePage(1, 10)
}
search()
</script>

<style lang="scss" scoped>
</style>
